<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /*
      思路：因为题目百分百能跳到最后，我们只需要计算跳的次数，如果当前i==cover即走到了可走到范围的尽头，那么step+1
      同时cover=nextCover，说明消耗该步我们可以走到nextCover里的任意位置
      */
      var jump = function (nums) {
        let curCover = 0
        let nextCover = 0
        let step = 0
        for (let i = 0; i < nums.length; i++) {
          nextCover = Math.max(nums[i] + i, nextCover)
          if (i == curCover) {
            step++
            curCover = nextCover
            if (curCover >= nums.length - 1) return step
          }
        }
      }
    </script>
  </body>
</html>
